package Tests
{
	import Box2D.Collision.Shapes.b2EdgeShape;
	import Box2D.Collision.Shapes.b2PolygonShape;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2BodyDef;
	import Box2D.Dynamics.b2BodyType;
	
	import Framework.Test;
	
	import org.osmf.layout.AbsoluteLayoutFacet;
	
	public class Pyramid extends Test
	{
		private static const e_count:int = 20;
		public function Pyramid()
		{
			super();
			createGround();
			createShapes();
		}
		private function createGround():void{
			var bd:b2BodyDef = new b2BodyDef;
			var ground:b2Body = m_world.CreateBody(bd);
			
			var shape:b2EdgeShape = new b2EdgeShape;
			shape.Set(new b2Vec2(-40,0),new b2Vec2(40,0));
			ground.CreateFixtureByShape(shape,0);
		}
		private function createShapes():void{
			var a:Number = .5;
			var shape:b2PolygonShape = new b2PolygonShape;
			shape.SetAsBox(a,a);
			
			var x:b2Vec2 = new b2Vec2(-7,.75);
			var y:b2Vec2 = new b2Vec2;
			var deltaX:b2Vec2 = new b2Vec2(0.5625, 1.25);
			var deltaY:b2Vec2 = new b2Vec2(1.125, 0.0);
			
			for (var i:int = 0; i < e_count; ++i)
			{
				y.Copy(x);
				
				for (var j:int = i; j < e_count; ++j)
				{
					var bd:b2BodyDef = new b2BodyDef;
					bd.type = b2BodyType.b2_dynamicBody;
					bd.position = y;
					var body:b2Body = m_world.CreateBody(bd);
					body.CreateFixtureByShape(shape, 5.0);
					
					y = y.Add(deltaY);
				}
				
				x  = x.Add(deltaX);
			}
		}
	}
}